<template>
  <div class="content">
    <!-- <div class="header">
      <div class="header_l">
        <img src="/img/datouxiang33@2x.png" alt="">
      </div>
      <div class="header_r">
        <div class="title">
          何振东的备课视频任务
        </div>
        <div class="state">
          待审批
        </div>
      </div>
    </div> -->
    <div class="body" style="position: relative;">
      <div class="title">
        课程名称
      </div>
      <div class="info">
        {{list.courseName}}-{{list.className}}
      </div>
      <div class="title">
        任务类型
      </div>
      <div class="info">
        {{list.renwuType}}
      </div>
      <div class="title">
        分派人员
      </div>
      <div class="info">
        {{list.bossUser}}
      </div>
      <div class="title">
        上传文件
      </div>
      <!-- 视频列表 -->
      <div class="videoList" v-if="type == '视频'">
        <img src="/img/videoTask/videoListImg.png" alt="" v-for="(item, index) in videoList" :key="index" @click="preVideo(item)">
      </div>
      <!-- 图片列表 -->
      <div class="bodyTop" v-if="type == '图片'">
        <img :src="item" alt="" v-for="(item, index) in images" :key="index" @click="preImg(index)">
      </div>
      <div class="title">
        截止时间
      </div>
      <div class="info">
        {{list.submitTime}}
      </div>
      <div class="title">
        分派时间
      </div>
      <div class="info">
        {{list.createTime}}
      </div>
      <div class="title" v-if="list.status == 2 || list.status == 3">
        审批意见
      </div>
      <div class="info lastInfo" v-if="list.status == 2 || list.status == 3">
        {{list.remark}}
      </div>
      <!-- 提交按钮 -->
      <van-button type="info" style="width:100%;position:absolute;bottom:0;left:0;" @click="toUpload(type)" v-if="list.status == 3">重新上传</van-button>
    </div>
    <!-- 视频预览 -->
    <div v-if="videoShow" @click="cancelVideo" class="videoMask">
      <div class="wrapper">
        <div>
          <video-player class="video-player vjs-custom-skin" ref="videoPlayer" :playsinline="true" :options="playerOptions">
          </video-player>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { ImagePreview } from "vant";
export default {
  data() {
    return {
      taskId: "",
      videoShow: false,
      playerOptions: {
        playbackRates: [0.5, 1.0, 1.5, 2.0], //倍速控制
        autoplay: false, //是否自动播放
        muted: false, //是否静音播放
        loop: false, //是否循环播放
        preload: "auto",
        language: "zh-CN", //语言，还要引入对应的文件
        aspectRatio: "16:9", //比例
        fluid: true,
        sources: [
          {
            type: "",
            src: "", //url地址
          },
        ],
        poster: "", //你的封面地址
        notSupportedMessage: "此视频暂无法播放，请稍后再试",
        controlBar: {
          timeDivider: true,
          durationDisplay: true, //剩余时间是否显示
          remainingTimeDisplay: false, //剩余时间是否显示，有一个即可
          fullscreenToggle: true, //全屏按钮
        },
      },
      // 页面数据
      list: {},
      // 视频列表
      videoList: [],
      // 图片列表
      images: [],
      // 类型
      type: "",
    };
  },
  mounted() {
    this.taskId = this.$route.query.id;
    this.list = this.$route.query.data;
    this.type = this.$route.query.type;
    if (this.type == "视频") {
      this.queryVideo();
    }
    if (this.type == "图片") {
      this.queryImg();
    }
  },
  methods: {
    // 详情数据
    queryVideo() {
      (async () => {
        const { data } = await this.get("/approve/queryBeiKeFile", {
          taskId: this.taskId,
        });
        this.videoList = data;
      })();
    },
    // 图片详情
    queryImg() {
      (async () => {
        const { data } = await this.get("/approve/queryBeiKeFile", {
          taskId: this.taskId,
        });
        for (var i = 0; i < data.length; i++) {
          this.images.push(data[i].beikeFile);
        }
      })();
    },
    // 待审批  预览视频
    preVideo(item) {
      this.playerOptions.sources[0].src = item.beikeFile;
      this.$toast.loading({
        message: "加载中",
        duration: 500,
        onClose: () => {
          this.videoShow = true;
        },
      });
    },
    cancelVideo() {
      this.videoShow = false;
    },
    // 预览图片
    preImg(index) {
      ImagePreview({
        images: this.images,
        startPosition: index,
        onClose() {
          // do something
        },
      });
    },
    // 上传文件
    toUpload(type) {
      if (type == "视频") {
        this.$router.push({
          path: "/uploadFile",
          query: {
            id: this.taskId,
            status: "已驳回",
          },
        });
      } else if (type == "图片") {
        this.$router.push({
          path: "/uploadImgFile",
          query: {
            id: this.taskId,
            status: "已驳回",
          },
        });
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.content {
  font-size: 0.1rem;
  width: 100%;
  height: 100%;
  padding: 0.24rem 0;
  box-sizing: border-box;
  //   background-color: #f7f9fa;
  //   .header {
  //     width: 100%;
  //     height: 1.3rem;
  //     background-color: #f7f9fa;
  //     display: flex;
  //     align-items: center;
  //     padding: 0 0.24rem;
  //     box-sizing: border-box;
  //     .header_l {
  //       margin-right: 0.17rem;
  //       img {
  //         width: 0.72rem;
  //         height: 0.72rem;
  //       }
  //     }
  //     .header_r {
  //       .title {
  //         // width: 3.06rem;
  //         font-size: 0.3rem;
  //         line-height: 0.3rem;
  //         font-family: PingFang SC;
  //         font-weight: bold;
  //         color: #343434;
  //       }
  //       .state {
  //         font-size: 0.24rem;
  //         line-height: 0.24rem;
  //         font-family: PingFang SC;
  //         font-weight: 400;
  //         color: #fa742a;
  //         margin-top: 0.17rem;
  //       }
  //     }
  //   }
  .body {
    box-sizing: border-box;
    width: 7.02rem;
    height: 100%;
    background-color: #f7f9fa;
    margin: 0 auto;
    padding: 0.31rem 0.23rem 0.31rem;
    box-sizing: border-box;
    border-radius: 0.02rem;
    .title {
      font-size: 0.26rem;
      line-height: 0.26rem;
      font-family: PingFang SC;
      font-weight: 400;
      color: #787878;
    }
    .info {
      font-size: 0.28rem;
      line-height: 0.28rem;
      font-family: PingFang SC;
      font-weight: bold;
      color: #343434;
      margin-top: 0.16rem;
      margin-bottom: 0.31rem;
    }
    .lastInfo {
      margin-bottom: 0;
    }
    .videoList {
      width: 6rem;
      display: flex;
      flex-wrap: wrap;
      margin-bottom: 0.31rem;
      img {
        width: 0.94rem;
        height: 0.94rem;
        margin-right: 0.2rem;
        margin-top: 0.2rem;
      }
    }
    .bodyTop {
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      margin-top: 0.31rem;
      img {
        width: 1.44rem;
        height: 1.44rem;
        border-radius: 0.06rem;
        margin-right: 0.16rem;
        margin-bottom: 0.16rem;
      }
    }
    .bodyTop img:nth-child(4n) {
      margin-right: 0;
    }
    .bodyTop img:last-child {
      margin-right: 0;
    }
  }
  .videoMask {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    .wrapper {
      display: flex;
      align-items: center;
      justify-content: center;
      height: 100%;
      div {
        width: 100%;
      }
    }
  }
}
</style>